package com.lz.kafka.producer.project.kafka.controller;

import cn.hutool.core.date.DateUtil;
import com.lz.kafka.producer.common.ResponseVo;
import com.lz.kafka.producer.project.kafka.service.KafkaProducerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping(value = "/kfk")
public class KafkaController {

    @Resource
    private KafkaProducerService kafkaProducerService;

    @GetMapping("/produce")
    public ResponseVo producer() {
        String topic = "topicfirst";
        for (int i = 0; i < 10; i++) {
            kafkaProducerService.sendMessage(topic, String.valueOf(i), "时间:" + DateUtil.current() + "生产 kafka " + i);
        }
        return ResponseVo.success(topic);
    }
}
